package com.itheima.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.itheima.dao.ReportDao;
import com.itheima.service.ReportService;
import com.itheima.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;

@Service(interfaceClass = ReportService.class)
@Transactional
public class ReportServiceImpl implements ReportService {
    @Autowired
    private ReportDao reportDao;

    /**
     * 获得运营统计数据
     * Map数据格式：
     *      todayNewMember -> number
     *      totalMember -> number
     *      thisWeekNewMember -> number
     *      thisMonthNewMember -> number
     *      todayOrderNumber -> number
     *      todayVisitsNumber -> number
     *      thisWeekOrderNumber -> number
     *      thisWeekVisitsNumber -> number
     *      thisMonthOrderNumber -> number
     *      thisMonthVisitsNumber -> number
     *      hotSetmeals -> List<Setmeal>
     */
    @Override
    public Map<String, Object> getBusinessReport() throws Exception {
        //获得当前日期
        String today = DateUtils.parseDate2String(DateUtils.getToday());
        //获得本周一的日期
        String thisWeekMonday = DateUtils.parseDate2String(DateUtils.getThisWeekMonday());
        //获得本月第一天的日期
        String firstDay4ThisMonth =
                DateUtils.parseDate2String(DateUtils.getFirstDay4ThisMonth());
        Map<String,Object> map = new HashMap<>();
        //获得今日新增会员
        Integer todayNewMember = reportDao.getTodayNewMember(today);
        //获取会员总数
        Integer totalMember = reportDao.getTotalMember();
        //本周新增会员
        Integer weekNewMember = reportDao.getNewMember(thisWeekMonday);
        //本月新增会员
        Integer monthNewMember = reportDao.getNewMember(firstDay4ThisMonth);
        //今日预约数
        Integer todayOrderNumber = reportDao.getTodayOrderNumber(today);
        //今日到诊人数
        Integer todayVisitsNumber = reportDao.getTodayVisitsNumber(today);
        //本周预约人数
        Integer weekOrderNumber = reportDao.getOrderNumber(thisWeekMonday);
        //本周到诊人数
        Integer weekVisitsNumber = reportDao.getVisitsNumber(thisWeekMonday);
        //本月预约人数
        Integer monthOrderNumber = reportDao.getOrderNumber(firstDay4ThisMonth);
        //本月到诊人数
        Integer monthVisitsNumber = reportDao.getVisitsNumber(firstDay4ThisMonth);

        map.put("reportDate",today);
        map.put("todayNewMember",todayNewMember);
        map.put("totalMember",totalMember);
        map.put("thisWeekNewMember",weekNewMember);
        map.put("thisMonthNewMember",monthNewMember);
        map.put("todayOrderNumber",todayOrderNumber);
        map.put("todayVisitsNumber",todayVisitsNumber);
        map.put("thisWeekOrderNumber",weekOrderNumber);
        map.put("thisWeekVisitsNumber",weekVisitsNumber);
        map.put("thisMonthOrderNumber",monthOrderNumber);
        map.put("thisMonthVisitsNumber",monthVisitsNumber);
        //热门套餐
        List<Map<String,Object>> list = reportDao.getHotSetmeal();
        map.put("hotSetmeal",list);
        return map;
    }
}
